home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 11 / Mac Magazin and MacEasy Magazine CD - Issue 11.iso / Sharewarebibliothek / Entwickler / WASTE 1.1b1 Distribution / Demo Source / WEDemoAbout.p < prev    next >
Text File  |  1995-06-01  |  3KB  |  141 lines

  1. unit WEDemoAbout;
  2.  
  3. { WASTE DEMO PROJECT: }
  4. { About Boxes }
  5.  
  6. { Copyright © 1993-1995 Marco Piovanelli }
  7. { All Rights Reserved }
  8.  
  9. interface
  10.     uses
  11.         WEDemoIntf;
  12.  
  13.     procedure DoAboutBox (dialogID: Integer);
  14.  
  15. implementation
  16.     uses
  17.         DialogUtils;
  18.  
  19.     const
  20.  
  21. { dialog item numbers }
  22.  
  23.         kItemTextPane = 3;
  24.  
  25.     var
  26.  
  27. { static variables }
  28.  
  29.         sBoxPainter: UserItemUPP;
  30.  
  31.     function WETextBox (textResID: Integer;
  32.                                     bounds: Rect;
  33.                                     alignment: Integer): OSErr;
  34.         label
  35.             1;
  36.         var
  37.             hWE: WEHandle;
  38.             longBounds: LongRect;
  39.             hText: Handle;
  40.             hStyles: Handle;
  41.             saveTextState, saveStylesState: SignedByte;
  42.             err: OSErr;
  43.     begin
  44.         hWE := nil;
  45.         hText := nil;
  46.         hStyles := nil;
  47.  
  48. { create a new WE instance }
  49.         WERectToLongRect(bounds, longBounds);
  50.         err := WENew(longBounds, longBounds, 0, hWE);
  51.         if (err <> noErr) then
  52.             goto 1;
  53.  
  54. { set the alignment style }
  55.         WESetAlignment(alignment, hWE);
  56.  
  57. { load the styl resource and make it unpurgeable }
  58.         hStyles := GetResource(kTypeStyles, textResID);
  59.         err := ResError;
  60.         if (err <> noErr) then
  61.             goto 1;
  62.         saveStylesState := HGetState(hStyles);
  63.         HNoPurge(hStyles);
  64.  
  65. { load the TEXT resource and lock it }
  66.         hText := GetResource(kTypeText, textResID);
  67.         err := ResError;
  68.         if (err <> noErr) then
  69.             goto 1;
  70.         saveTextState := HGetState(hText);
  71.         HLockHi(hText);
  72.  
  73. { insert the text }
  74.         err := WEInsert(hText^, GetHandleSize(hText), StScrpHandle(hStyles), nil, hWE);
  75.         if (err <> noErr) then
  76.             goto 1;
  77.  
  78. { clear result code }
  79.         err := noErr;
  80.  
  81. 1:
  82. { clean up }
  83.         if (hText <> nil) then
  84.             HSetState(hText, saveTextState);
  85.  
  86.         if (hStyles <> nil) then
  87.             HSetState(hStyles, saveStylesState);
  88.  
  89.         WEDispose(hWE);
  90.  
  91. { return result code }
  92.         WETextBox := err;
  93.  
  94.     end;  { WETextBox }
  95.  
  96.     procedure DrawUserItem (dialog: DialogPtr;
  97.                                     item: Integer);
  98.     begin
  99.  
  100. { draw the text, centered, in the item rect }
  101.         if (WETextBox(GetWRefCon(dialog), GetDialogItemRect(dialog, item), weCenter) <> noErr) then
  102.             ;
  103.     end;  { DrawUserItem }
  104.  
  105.     procedure DoAboutBox (dialogID: Integer);
  106.         var
  107.             aboutBox: DialogPtr;
  108.             itemHit: Integer;
  109.     begin
  110.  
  111. { get about box }
  112.         aboutBox := GetNewDialog(dialogID, nil, WindowPtr(-1));
  113.         if (aboutBox = nil) then
  114.             Exit(DoAboutBox);
  115.  
  116. { install a user item drawing procedure for the text pane }
  117.         if (sBoxPainter = nil) then
  118.             sBoxPainter := NewUserItemProc(@DrawUserItem);
  119.         SetDialogItemProc(aboutBox, kItemTextPane, sBoxPainter);
  120.  
  121. { store ID of TEXT/styl pair (= ID of dialog template) in dialog refCon }
  122.         SetWRefCon(aboutBox, dialogID);
  123.  
  124. { put up the dialog }
  125. {$IFC NOT UNDEFINED THINK_PASCAL}
  126.         SetCursor(arrow);
  127. {$ELSEC}
  128.         SetCursor(qd.arrow);
  129. {$ENDC}
  130.         ShowWindow(aboutBox);
  131.         SetPort(aboutBox);
  132.  
  133. { wait for a click }
  134.         ModalDialog(GetMyStandardDialogFilter, itemHit);
  135.  
  136. { bring down the dialog }
  137.         DisposeDialog(aboutBox);
  138.  
  139.     end;  { DoAboutBox }
  140.  
  141. end.